# !/bin/bash

CURRENT_DIR=$(
    cd "$(dirname "$0")"
    pwd
)

# 进入部署目录
cd ${CURRENT_DIR}

# 回到上一级
cd ../

if which java > /dev/null; then
    echo "Java环境已安装"
else
    echo "未安装Java环境"
    exit
fi

name=zbp-job-executor
jar=$name.jar

echo "$(date)------- 开始关闭执行器服务 --------"
server_pid=$(netstat -anp|grep 15001|awk '{printf $7}'|cut -d/ -f1)
echo "$(date)-pid: $server_pid"
if [ "$server_pid" == "" ]
  then
    echo "$(date)------- 成功关闭执行器服务 --------"
 else
    echo "$(date)-TOMCAT PID: $server_pid"
    kill -9 "$server_pid"
    echo "$(date)------- 成功关闭执行器服务 --------"
fi

# 启动服务
echo "$(date)------- 启动执行器服务 --------"
nohup java -jar -server -Xmx2g $jar $name --spring.config.location=application.yml  > /dev/null 2>&1 &

echo "$(date)------- 执行器服务成功 --------"
